from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

driver = webdriver.Edge()
driver.maximize_window()
driver.get('https://www.jiuxian.com/')
time.sleep(1)

driver.find_element(By.CLASS_NAME,'headerLogin').click()
time.sleep(1)
driver.find_element(By.ID,'userName').send_keys('18620064667')
WebDriverWait(driver,20,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="userName"]')))
password = driver.find_element(By.ID,'password')
password.send_keys('Yukaiwen2580')
print(password.get_attribute('value'))
time.sleep(10)
driver.find_element(By.ID,'save').click()
driver.implicitly_wait(10)
driver.find_element(By.CLASS_NAME,'bindSub').click()
time.sleep(3)
sou = driver.find_element(By.XPATH,'//input[@id="wd" and @class="search-form"]')
sou.send_keys('茅台')
print(sou.size)
print(sou.is_displayed())
time.sleep(1)
driver.find_element(By.XPATH,'/html/body/div[4]/div/div[2]/div[1]/form/input[2]').click()
time.sleep(1)
driver.find_element(By.XPATH,'//img[@src="https://img08.jiuxian.com/2025/0707/0ef5c7123edf47f38acc0f90f10262ba4.jpg"]').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(1)
driver.find_element(By.NAME,'detail_jiarugouwuche').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(2)
driver.find_element(By.CLASS_NAME,'u-buy-go').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(1)